package thread.demo.synchronousQueue;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class SynchronousQueue_Poll {
  public static void main(String[] args) throws InterruptedException {
    SynchronousQueue<String> queue = new SynchronousQueue<>();
    
    String consumerMessage = "消息";
    new Thread(() -> {
      // 直接消费，如果队列中无“生产者”的话，直接返回null
      System.out.println(queue.poll());
    }).start();
    
    TimeUnit.MILLISECONDS.sleep(100);
    
     new Thread(() -> {
       queue.offer(consumerMessage);
     }).start();
  }
}
